<?php
/**
 * 订单评论数据模型
 *
 * PHP version 5
 *
 * @package   YHG
 * @author    Fee <Fee@shorigo.com>
 * @copyright 2015 SRG Inc.
 */
namespace Common\Model;
use Think\Model\RelationModel;
class CommentsModel extends RelationModel {

    protected $tableName = 'comments'; 
    
    /**
     * 设置主键
     *
     * @author Fee
     */
    protected $pk        = 'comm_id';

    /**
     * 自动验证
     *
     * @author Fee
     */
    protected $_validate = array(
        array('order_id',   'require', '订单ID不能为空'),
        array('phone',   'require', '手机号码不能为空'),
        array("content",   'require', '评论不能为空'),
    );

    /**
     * 自动完成
     *
     * @author Fee
     */
    protected $_auto     = array(
        array('order_id', 'intval', 3, 'function'),
        array('phone', 'remove_xss', 3, 'function'),
        array('content', 'remove_xss', 3, 'function'),
        array('add_time',      'time', 1, 'function'),
    );

    /**
     * 关联
     *
     * @author Fee
     */
    protected $_link = array(
        'Orders' => array(  //机型表
            'mapping_type'  => self::BELONGS_TO,
            'class_name'    => 'Orders',
            'foreign_key'   => 'order_id',
            'mapping_name'  => 'order',
            'mapping_fields'   => 'type_id,add_time,order_price,user_phone',
        ),
        'Types' => array(  //机型表
            'mapping_type'  => self::BELONGS_TO,
            'class_name'    => 'Types',
            'foreign_key'   => 'type_id',
            'mapping_name'  => 'types',
            'mapping_fields'   => 'type_name,type_photo',
        ),
    );

}
?>